package com.kevin.mediator;

import java.util.ArrayList;
import java.util.List;

/**
 * 具体中介者
 *
 * @author kevin
 * @date 2025/8/22
 */
public class ConcreteMediator extends Mediator{

    // 同事类集合
    private List<Colleague> colleagueList = new ArrayList<>();

    @Override
    public void register(Colleague colleague) {
        if (!colleagueList.contains(colleague)){
            colleagueList.add(colleague);
            colleague.setMediator(this);
        }
    }

    @Override
    public void relay(Colleague colleague) {
        for (Colleague col : colleagueList) {
           if (col.equals(colleague)){
               col.receive();
           }
        }
    }
}
